﻿@using SmartStore.Web.Models.Customer;
@model CustomerOrderListModel
@{
	Html.AddTitleParts(T("PageTitle.Account").Text);

	Layout = "_MyAccount";
	ViewBag.PageClassToken = "orders";
	ViewBag.PageTitle = T("Account.CustomerOrders").Text;
}

@if (Model.RecurringOrders.Count > 0)
{
    using (Html.BeginForm())
    {
        <div class="recurring-payments mb-3">
            <div class="section-title">
                @T("Account.CustomerOrders.RecurringOrders")
            </div>

            <div><hr /></div>

            <div class="recurring-payments-box table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th>
                                @T("Account.CustomerOrders.RecurringOrders.StartDate")
                            </th>
                            <th>
                                @T("Account.CustomerOrders.RecurringOrders.CycleInfo")
                            </th>
                            <th >
                                @T("Account.CustomerOrders.RecurringOrders.NextPayment")
                            </th>
                            <th>
                                @T("Account.CustomerOrders.RecurringOrders.TotalCycles")
                            </th>
                            <th>
                                @T("Account.CustomerOrders.RecurringOrders.CyclesRemaining")
                            </th>
                            <th>
                                @T("Account.CustomerOrders.RecurringOrders.InitialOrder")
                            </th>
                            <th>
                                @T("Account.CustomerOrders.RecurringOrders.Cancel")
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.RecurringOrders)
                        {
                            <tr>
                                <td>
                                    @item.StartDate
                                </td>
                                <td>
                                    @item.CycleInfo
                                </td>
                                <td>
                                    @item.NextPayment
                                </td>
                                <td>
                                    @item.TotalCycles
                                </td>
                                <td>
                                    @item.CyclesRemaining
                                </td>
                                <td>
									<a class="btn btn-secondary" href="@Url.Action("Details", "Order", new { id = item.InitialOrderId })" rel="nofollow">
										<i class="far fa-list-alt"></i>
										@string.Format(@T("Account.CustomerOrders.RecurringOrders.ViewInitialOrder").Text, item.InitialOrderId)
									</a>
                                </td>
                                <td>
                                    @if (item.CanCancel)
                                    {
                                        <button type="submit" name="cancelRecurringPayment@(item.Id)" class="btn btn-danger">
											<i class="far fa-trash-alt"></i>
                                            @T("Account.CustomerOrders.RecurringOrders.Cancel")
                                        </button>
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
    }

    if (Model.CancelRecurringPaymentErrors.Count > 0)
    {
        <div class="alert alert-danger">
            @for (int i = 0; i < Model.CancelRecurringPaymentErrors.Count; i++)
            {
                <p>@Model.CancelRecurringPaymentErrors[i]</p>
            }
        </div>
    }
}

@if (Model.Orders.Count == 0)
{
	<div class="alert alert-warning">
		@T("Account.CustomerOrders.NoOrders")
	</div>
	return;
}

<div class="card-deck card-cols-sm-1 order-list">
    @foreach (var order in Model.Orders)
    {
        <div class="card shadow-sm order-item">
			<div class="card-body">
				<h4 class="card-title mb-4">@T("Order.Order#"): @order.OrderNumber</h4>
				<dl class="row mb-0">
					<dt class="col-sm-3 font-weight-400 text-muted">@T("Order.OrderStatus")</dt>
					<dd class="col-sm-9">@order.OrderStatus</dd>
					<dt class="col-sm-3 font-weight-400 text-muted">@T("Order.OrderDate")</dt>
					<dd class="col-sm-9">@order.CreatedOn.ToNativeString()</dd>
					<dt class="col-sm-3 font-weight-400 text-muted">@T("Order.OrderTotal")</dt>
					<dd class="col-sm-9 price">@order.OrderTotal</dd>
				</dl>
			</div>

			<div class="card-footer d-flex p-0">
				<a class="btn btn-secondary btn-flat rounded-0" href="@Url.Action("Details", "Order", new { id = order.Id })" rel="nofollow">
					<i class="far fa-list-alt"></i>
					<span>@T("Order.OrderDetails")</span>
				</a>
				@if (order.IsReturnRequestAllowed)
				{
					<a class="btn btn-secondary btn-flat rounded-0" href="@Url.Action("ReturnRequest", "ReturnRequest", new { id = order.Id })" rel="nofollow">
						<i class="fa fa-reply"></i>
						<span>@T("Account.CustomerOrders.ReturnItems")</span>
					</a>
				}
			</div>
        </div>
    }
</div>
@if (Model.Orders.TotalPages > 1)
{
	<div class="mt-1">
		@Html.SmartStore().Pager(Model.Orders).Name("paginator").QueryParam("page").Action("Orders", "Customer")
	</div>
}
